#include "mycoin.h"
#include <QDebug>


MyCoin::MyCoin(QString img)
{
    QPixmap pix;
    bool ret=pix.load(img);
    if(!ret)
    {
        QString str=QString("图片加载失败，失败路径为%1！").arg(img);
        qDebug()<<str;
        return;
    }
    //设置金币固定尺寸
    this->setFixedSize(pix.width(),pix.height());
    //设置不规则样式
    this->setStyleSheet("QPushButton{border:0px;}");
    //设置图标
    this->setIcon(pix);
    //设置图标大小
    this->setIconSize(QSize(pix.width(),pix.height()));

    //创建定时器
    this->timer1=new QTimer(this);
    this->timer2=new QTimer(this);

    //监听金币翻银币的计时器
    connect(this->timer1,&QTimer::timeout,[=](){
        QPixmap pix;
        QString str=QString(":/res/Coin000%1.png").arg(this->min++);
        bool ret=pix.load(str);
        if(!ret)
        {
            QString str=QString("图片加载失败，失败路径为%1！").arg(str);
            qDebug()<<str;
            return;
        }
        //设置金币固定尺寸
        this->setFixedSize(pix.width(),pix.height());
        //设置不规则样式
        this->setStyleSheet("QPushButton{border:0px;}");
        //设置图标
        this->setIcon(pix);
        //设置图标大小
        this->setIconSize(QSize(pix.width(),pix.height()));

        if(this->min>this->max)
        {
            this->min=1;
            this->timer1->stop();
        }
    });

}

//点击硬币调用的函数，改变正反标志
void MyCoin::changeFlag()
{
    if(this->flag)
    {
        this->timer1->start(30);
        this->flag=false;
    }
    else{
        this->timer2->start(30);
        this->flag=true;
    }

}
